package org.zuoye.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.zuoye.Dao.liuyanDao;
import org.zuoye.DaoImp.liuyanDaoimp;
import org.zuoye.bean.Liuyan;
import org.zuoye.bean.UserLogin;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class liuyanAction extends ActionSupport {//简单的分页功能
	private List<Liuyan> liuyans=new ArrayList<>();
	private int pageNow = 1 ; //初始化为1,默认从第一页开始显示  
    private int pageSize = 7; //每页显示7条记录
    private String log="---留言内容---";
    private String title;
    private String neirong;
    liuyanDao lyDao=new liuyanDaoimp();
	public List<Liuyan> getLiuyans() {
		return liuyans;
	}
	public void setLiuyans(List<Liuyan> liuyans) {
		this.liuyans = liuyans;
	}
	public int getPageNow() {
		return pageNow;
	}
	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public String getLog() {
		return log;
	}
	public void setLog(String log) {
		this.log = log;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getNeirong() {
		return neirong;
	}
	public void setNeirong(String neirong) {
		this.neirong = neirong;
	}
	
	public String execute() throws Exception{
		Map<String, Object> session = ActionContext.getContext().getSession();	//获得会话，用来获取当前登录的用户
		UserLogin  user=(UserLogin) session.get("login");
		String isAdmin=user.getUserIsAdmin();
		liuyans=lyDao.getLiuyan(pageSize, pageNow);
		if(liuyans.size()==0)
			setLog("---没有了---");
		if(isAdmin.equals("YES")){
			return SUCCESS;
		}
		else {
			return "student";
		}
		
	}
	public String addLiuyan() throws Exception{
		Map<String, Object> session = ActionContext.getContext().getSession();	//获得会话，用来获取当前登录的用户
		UserLogin  user=(UserLogin) session.get("login");
		String userNAME=user.getUserName();
		System.out.println("用户："+userNAME);
		System.out.println("标题"+title);
		System.out.println("内容"+neirong);
		Liuyan L=new Liuyan();
		L.setUserName(userNAME);
		L.setTitle(title);
		L.setNeirong(neirong);
		lyDao.addLiuyan(L);
		return SUCCESS;
	}
	
}
